package com.example.websocket.websocket.Mapper;

import com.example.websocket.websocket.pojo.MessageRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageRecordMapper {
    @Insert("insert into tb_messagerecord(id,fromuser,touser,message,time) values(#{id},#{fromUser},#{toUser},#{message},#{time})")
    void insert(MessageRecord messageRecord);

    @Select("select * from tb_messagerecord where (touser=#{toUser} and fromuser=#{fromUser}) " +
            "or (touser=#{fromUser} and fromuser=#{toUser}) order by time")
    List<MessageRecord> getMessage(@Param("toUser") String toUser,@Param("fromUser") String fromUser);

    /**
     * 获取我发送的消息的聊天好友
     * @param username
     * @return
     */
    @Select("select distinct touser from tb_messagerecord where fromuser=#{username}  ")
    List<String> getChatFriend1(String username);

    /**
     * 获取发送给我消息的聊天好友，当当我没回的时候能看得到
     * @param username
     * @return
     */
    @Select("select distinct fromuser from tb_messagerecord where touser=#{username} ")
    List<String> getChatFriend2(String username);
}
